package xyz.jangle.date;

import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
public class TimeStrTest {

	public static void main(String[] args) {
		
		LocalTime time = LocalTime.now();
		LocalTime time2 = time.minusHours(1);
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
		String str = formatter.format(time2);
		System.out.println(str);
		
		// 时间字符串转本地时间
		LocalTime parse = LocalTime.parse(str);
		System.out.println(parse);
		
		// 日期字符串转本地日期
		String str2 = "2025-07-14";
		DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
		LocalDate parse2 = LocalDate.parse(str2, formatter2);
		System.out.println(parse2);
		
		// 日期转时间戳
		LocalDateTime now = LocalDateTime.now();
		Timestamp timestamp = Timestamp.valueOf(now);
		System.out.println(timestamp);
		Timestamp timestamp2 = Timestamp.valueOf("2025-07-14 08:57:00");
		System.out.println(timestamp2);

	}

}
